package com.haircut.base;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 响应码枚举
 *

 * @since 2020-06-23
 **/
@AllArgsConstructor
@NoArgsConstructor
public enum ResultCode implements IResultCode, Serializable {

    SUCCESS(0, "一切ok"),

    USER_ERROR(10001, "用户端错误"),
    REPEAT_SUBMIT_ERROR(10002, "您的请求已提交，请不要重复提交或等待片刻再尝试。"),

    USER_LOGIN_ERROR(10200, "用户登录异常"),

    USER_NOT_EXIST(10201, "用户不存在"),
    USER_ACCOUNT_LOCKED(10202, "用户账户被冻结"),
    USER_ACCOUNT_INVALID(10203, "用户账户已作废"),

    USERNAME_OR_PASSWORD_ERROR(10210, "用户名或密码错误"),
    PASSWORD_ENTER_EXCEED_LIMIT(10211, "用户输入密码次数超限"),
    CLIENT_AUTHENTICATION_FAILED(10212, "客户端认证失败"),

    VERIFY_CODE_TIMEOUT(10213, "验证码已过期"),
    VERIFY_CODE_ERROR(10214, "验证码错误"),

    TOKEN_INVALID(10230, "token无效或已过期"),
    TOKEN_ACCESS_FORBIDDEN(10231, "token已被禁止访问"),

    AUTHORIZED_ERROR(10300, "访问权限异常"),
    ACCESS_UNAUTHORIZED(10301, "访问未授权"),
    FORBIDDEN_OPERATION(10302, "演示环境禁止新增、修改和删除数据，请本地部署后测试"),


    PARAM_ERROR(10400, "用户请求参数错误"),
    RESOURCE_NOT_FOUND(10401, "请求资源不存在"),
    PARAM_IS_NULL(10410, "请求必填参数为空"),

    USER_UPLOAD_FILE_ERROR(10700, "用户上传文件异常"),
    USER_UPLOAD_FILE_TYPE_NOT_MATCH(10701, "用户上传文件类型不匹配"),
    USER_UPLOAD_FILE_SIZE_EXCEEDS(10702, "用户上传文件太大"),
    USER_UPLOAD_IMAGE_SIZE_EXCEEDS(10703, "用户上传图片太大"),

    SYSTEM_EXECUTION_ERROR(20001, "系统执行出错"),
    SYSTEM_EXECUTION_TIMEOUT(20100, "系统执行超时"),
    SYSTEM_ORDER_PROCESSING_TIMEOUT(20100, "系统订单处理超时"),

    SYSTEM_DISASTER_RECOVERY_TRIGGER(20200, "系统容灾功能被出发"),
    FLOW_LIMITING(20210, "系统限流"),
    DEGRADATION(20220, "系统功能降级"),

    SYSTEM_RESOURCE_ERROR(20300, "系统资源异常"),
    SYSTEM_RESOURCE_EXHAUSTION(20310, "系统资源耗尽"),
    SYSTEM_RESOURCE_ACCESS_ERROR(20320, "系统资源访问异常"),
    SYSTEM_READ_DISK_FILE_ERROR(20321, "系统读取磁盘文件失败"),

    CALL_THIRD_PARTY_SERVICE_ERROR(30001, "调用第三方服务出错"),
    MIDDLEWARE_SERVICE_ERROR(30100, "中间件服务出错"),
    INTERFACE_NOT_EXIST(30113, "接口不存在"),

    MESSAGE_SERVICE_ERROR(30120, "消息服务出错"),
    MESSAGE_DELIVERY_ERROR(30121, "消息投递出错"),
    MESSAGE_CONSUMPTION_ERROR(30122, "消息消费出错"),
    MESSAGE_SUBSCRIPTION_ERROR(30123, "消息订阅出错"),
    MESSAGE_GROUP_NOT_FOUND(30124, "消息分组未查到"),

    DATABASE_ERROR(30300, "数据库服务出错"),
    DATABASE_TABLE_NOT_EXIST(30311, "表不存在"),
    DATABASE_COLUMN_NOT_EXIST(30312, "列不存在"),
    DATABASE_DUPLICATE_COLUMN_NAME(30321, "多表关联中存在多个相同名称的列"),
    DATABASE_DEADLOCK(30331, "数据库死锁"),
    DATABASE_PRIMARY_KEY_CONFLICT(30341, "主键冲突"),

    TXT2IMG_HAS_TASK_TODO(40001, "己有创作中的配图，请等待完成通知!"),
    TXT2IMG_GENERATE_PARAM_ERROR_ROLEID(40002,"输入角色错误"),
    TXT2IMG_GENERATE_PARAM_ERROR_CONTENT_LONG(40003,"输入文案过长"),
    TXT2IMG_GENERATE_PARAM_ERROR_CONTENT_SENSITIVE(40004,"输入文字包含敏感词，请重新输入"),
    TXT2IMG_USER_PENDING_TASK_LIMITED(40005, "用户创作队列已达上限!"),
    TXT2IMG_SERVER_PENDING_TASK_LIMITED(40006, "创作队列已达上限!"),
    TXT2IMG_INSUFFICIENT_USER_AMOUNT(40007, "用户余额不够!"),
    VOICE2VIDEO_ROLE_CANNOT_USE(50001, "该角色不能使用绘声!"),
    VOICE2VIDEO_PARAM_IS_EMPTY(50002, "参数为空"),
    TASK_IS_NULL(50003, "任务不存在");

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    private Integer code;

    private String msg;

    @Override
    public String toString() {
        return "{" +
                "\"code\":\"" + code + '\"' +
                ", \"msg\":\"" + msg + '\"' +
                '}';
    }


    public static ResultCode getValue(String code){
        for (ResultCode value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return SYSTEM_EXECUTION_ERROR; // 默认系统执行错误
    }
}
